package com.learn.springmvc.util;

import org.springframework.core.convert.converter.Converter;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class StringToDate implements Converter<String, Date> {

    public Date convert(String str) {
        Date parses = null;
        if (str == null){
            throw new RuntimeException("参数为空");
        }
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd");

        try {
            parses = df.parse(str);
            
        } catch (ParseException e) {
            e.printStackTrace();
        }

        return parses;
    }
}
